<template>
	<view class="container" >
		<view class="status_bar">
			<view style="margin-left: 4%;" @tap="goBack()"><u-icon name="arrow-leftward" size='24' /></view>
			<view style="margin-left: -50upx; font-weight: bold;">黑名单</view>
			<view></view>
			</u-icon>
		</view>
		<view class="scroll-view-box">
			<scroll-view scroll-y class="list">
				<uni-swipe-action ref="swipe">
					<uni-swipe-action-item v-for="(item, index) in list" :key="index">
						<view class="shop-box">
							<view style="display: flex;">
								<view>
									<view style="border-radius: 30upx;margin-left: 10upx;" v-if="item.black_avatar">
										<u--image :showLoading="true" :src="item.black_avatar" width="120upx"
											height="120upx" radius="10upx"></u--image>
									</view>
									<view v-else class="name-img">{{item.black_name?item.black_name.substring(0,1):''}}
									</view>
								</view>
								<view style="margin: 40upx 0 0 30upx;">{{item.black_name}}</view>
								<!-- <view style="margin: 40upx 0 0 30upx;">{{item.update_time}}</view> -->
							</view>
							<view class="delete-btn" @tap="handleDelete(item.id)">删除</view>
						</view>
					</uni-swipe-action-item>
				</uni-swipe-action>
			</scroll-view>
		</view>




	</view>
</template>trash

<script>
	export default {
		data() {
			return {
				userId: uni.getStorageSync('userId') || '',
				startX: 0, // 触摸开始的X坐标
				endX: 0, // 触摸结束的X坐标
				threshold: 50, // 设置滑动多少距离后触发返回
				// 基本案列数据
				list: [{
						name: '哈哈哈',
						url: '../../../static/img/face.png',
						time: '11-12 16:02',
						disabled: false,
						title: '申请已通过'
					},
					{
						name: '嘻嘻嘻',
						time: '11-12 16:02',
						disabled: false,
						groupChat: "[群聊]",
						title: '坐席已创建'
					}
				],
				page: 1, // 当前页数
				pageSize: 5, // 每页条数
				hasMore: true, // 是否有更多数据
			}
		},
		onLoad() {

		},
		onShow() {
			this.getList()
			//this.getListAdd()
		},
		onReachBottom() {
			if (this.hasMore) {
				this.loadMore(); // 调用加载更多方法
			}
		},
		onPullDownRefresh() {
			this.refreshData(); // 调用刷新数据方法
		},
		mounted() {
			this.loadMore(); // 初始化时加载数据
		},
		methods: {
			goBack() {
				uni.navigateBack({
					delta: 1
				});
			},
			
			
			// 加载更多数据
			loadMore() {
				if (this.hasMore) {
					this.page++;
					this.getList();
				}
			},
			// 刷新数据
			refreshData() {
				// 模拟数据刷新
				setTimeout(() => {
					this.list = []; // 清空原有数据
					this.page = 1; // 重置页数
					this.loadMore(); // 加载新的数据
					uni.stopPullDownRefresh(); // 停止下拉刷新动作
				}, 1000);
			},
			getList() {
				uni.request({
					url: this.$api.baseUrl + '/api/common/black_list/fetch',
					header: {
						'content-type': 'application/json'
					},
					data: {
						user_id: uni.getStorageSync('userId'),
						page: this.page,
						page_size: this.pageSize,
					},
					method: 'POST',
					success: res => {
						// uni.hideLoading()
						if (res.data.code == 0) {
							this.list = res.data.data

						}
						if (res.data.data.length >= this.pageSize) {
							this.hasMore = true;
						} else {
							this.hasMore = false;
						}
					},
					fail: res => {
						console.log(res);
					}
				})
			},
			handleDelete(id) {
				console.log(id, 'id')
				uni.request({
					url: this.$api.baseUrl + '/api/common/black_list/delete',
					header: {
						'content-type': 'application/json'
					},
					data: {
						id: id
					},
					method: 'POST',
					success: res => {
						// uni.hideLoading()
						if (res.data.code == 0) {
							uni.showToast({
								title: res.data.message,
								//将值设置为 success 或者直接不用写icon这个参数
								icon: 'success',
								//显示持续时间为 2秒
								duration: 2000,
							})
							this.getList()

						}

					},
					fail: res => {
						uni.showToast({
							title: res.data.message,
							//将值设置为 success 或者直接不用写icon这个参数
							icon: 'none',
							//显示持续时间为 2秒
							duration: 2000,
						})
					}
				})

			}
			// getListAdd() {
			// 	uni.request({
			// 		url: this.$api.baseUrl + '/api/common/black_list/add',
			// 		header: {
			// 			'content-type': 'application/json'
			// 		},
			// 		data: {
			// 			user_id: uni.getStorageSync('userId'),
			// 			black_id: 400002, 
			// 			black_name: "122", 
			// 			black_avatar: "333" 
			// 		},
			// 		method: 'POST',
			// 		success: res => {
			// 			console.log(res.data.data, 'res');
			// 			// uni.hideLoading()
			// 			if (res.data.code == 0) {
			// 				this.dataList = res.data.data

			// 			}
			// 			console.log(this.list);
			// 			// this.list = res.data;
			// 		},
			// 		fail: res => {
			// 			console.log(res);
			// 		}
			// 	})
			// }
		}
	}
</script>

<style lang="scss" scoped>
	page {
		overflow: hidden;
	}

	.container {
		width: 100%;
		height: 100%;

	}

	.status_bar {
		display: flex;
		justify-content: space-between;
		align-items: center;
		margin-top: 50upx;
	}

	.status_bar,
	.head {
		background-color: #fff;
		height: 160upx;
	}

	.shop-box {
		width: 92%;
		margin-left: 4%;
		background-color: #fff;
		margin-top: 20upx;
		border-radius: 20upx;
		padding: 10upx 30upx;

		color: #2e2e2e;
		font-weight: 300;
		display: flex;
		justify-content: space-between;
		align-items: center;

		.delete-btn {
			border: 1upx #ccc solid;
			border-radius: 10upx;
			padding: 6upx 10upx;
			font-size: 26upx;
		}

	}

	.name-img {
		width: 120upx;
		height: 120upx;
		border-radius: 10upx;
		background: #d54827;
		font-size: 36upx;
		text-align: center;
		line-height: 120upx;
		color: #fff;
		margin-left: 10upx;
	}
</style>